Skip to content

Add X25519 non-blocking support and async example improvements#9721

Open
dgarske wants to merge 5 commits intowolfSSL:masterfrom
dgarske:x25519_nb
Open

Add X25519 non-blocking support and async example improvements#9721
dgarske wants to merge 5 commits intowolfSSL:masterfrom
dgarske:x25519_nb

Conversation

@dgarske
Copy link
Contributor

@dgarske dgarske commented Jan 29, 2026

Description

Add non-blocking (non-blocking crypto) support for Curve25519 (X25519) key generation and shared secret. This enables WC_X25519_NONBLOCK for use with TLS, similar to the existing WC_ECC_NONBLOCK support. Requires CURVE25519_SMALL (the small fe_low_mem.c implementation).

New Features

  • X25519 non-blocking key gen (wc_curve25519_make_key) and shared secret (wc_curve25519_shared_secret) using FP_WOULDBLOCK yield pattern.
  • Non-blocking curve25519_nb() function in fe_low_mem.c with state machine for iterative scalar multiplication.
  • TLS integration: WC_X25519_NONBLOCK support in src/tls.c and src/internal.c for key gen and ECDH during handshake.
  • New async TLS client/server examples (examples/async/) with standalone Makefile (no configure needed).
  • user_settings_curve25519nonblock.h example config.
  • Async examples CI workflow (.github/workflows/async-examples.yml).
  • WOLFSSL_STATIC_MEMORY support in async examples using wolfSSL_CTX_load_static_memory.

Fixes

  • Fix async SW guard in curve25519.c — require WOLFSSL_ASYNC_CRYPT_SW for software async simulation symbols.
  • Fix mutual auth in async examples — server loads self-signed client certs (ECC/ED25519) as their own CA.
  • Fix C90 mixed-declaration violations in SP ECC non-blocking code (sp_c32.c, sp_c64.c, sp_x86_64.c, sp_arm32.c, sp_arm64.c, sp_armthumb.c, sp_cortexm.c) — move typedef before statements.
  • Fix register ... asm() pedantic warning on macOS in sp_x86_64.c with __APPLE__ && __MACH__ guard.
  • Add missing user_settings_curve25519nonblock.h to examples/configs/include.am.

Testing

  • CI matrix tests async examples with: default, WOLFSSL_SMALL_CERT_VERIFY, WOLFSSL_STATIC_MEMORY.
  • 8 TLS test combinations per matrix entry: ECC/X25519 x TLS 1.2/1.3 x normal/mutual auth.
  • Validates WC_PENDING_E count >= 100 per test to confirm async crypto is exercised.
  • Static memory prints per-connection memory stats (peak mem, allocs, frees).
  • wolfcrypt/test/test.c updated with X25519 non-blocking test cases.
  • Tested: ./configure --enable-curve25519=small CFLAGS="-DWC_X25519_NONBLOCK" and ./configure CFLAGS="-DWC_X25519_NONBLOCK" --enable-curve25519=small --enable-asynccrypt.

@dgarske dgarske self-assigned this Jan 29, 2026
@dgarske dgarske marked this pull request as ready for review January 29, 2026 20:06
@dgarske dgarske force-pushed the x25519_nb branch 4 times, most recently from e8fc0a8 to 50dea8f Compare February 2, 2026 17:40
@night1rider
Copy link
Contributor

Jenkins retest this please - CI issue PRB-Master-Job

@dgarske
Copy link
Contributor Author

dgarske commented Feb 4, 2026

Jenkins retest this please

## Summary
- Add non-blocking (incremental) Curve25519 key generation and shared secret via `WC_X25519_NONBLOCK`, modeled after the existing ECC non-blocking pattern (`WC_ECC_NONBLOCK`)
- Implement `curve25519_nb()` and `fe_inv__distinct_nb()` in `fe_low_mem.c` as state-machine variants that return `FP_WOULDBLOCK` to yield after each field multiply
- Add `wc_curve25519_set_nonblock()` API to attach/detach non-blocking context to a key
- Integrate X25519 non-blocking with TLS 1.2/1.3 key share generation and shared secret in `tls.c` and `internal.c` (behind `WC_X25519_NONBLOCK && WOLFSSL_ASYNC_CRYPT_SW`)
- Add `--enable-curve25519=nonblock` configure option (auto-enables `--enable-asynccrypt` and `--enable-asynccrypt-sw`)
- Add X25519 async software dispatch cases in `async.c` and types in `async.h`
- Fix async guard in `curve25519.c` to require `WOLFSSL_ASYNC_CRYPT_SW` (matching other algorithms)
- Overhaul `examples/async/` client/server: non-blocking I/O via `WOLFSSL_USER_IO`, standalone `Makefile`, X25519/ECC mode selection, CI-friendly ready-file sync
- Add `examples/configs/user_settings_curve25519nonblock.h` and CI coverage in `os-check.yml` and new `async-examples.yml` workflow
- Add wolfcrypt test and API test coverage for X25519 non-blocking
@dgarske dgarske changed the title Support for Curve25519 non-blocking cryptography (based on PR #5764) Add X25519 non-blocking support and async example improvements Feb 5, 2026
@dgarske
Copy link
Contributor Author

dgarske commented Feb 5, 2026

Jenkins retest this please: "EOFException"

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds non-blocking (async crypto) support for Curve25519 (X25519) key generation and shared secret operations, enabling WC_X25519_NONBLOCK for use with TLS. The implementation requires CURVE25519_SMALL and follows the existing WC_ECC_NONBLOCK pattern using an FP_WOULDBLOCK yield mechanism.

Changes:

  • Adds X25519 non-blocking API (wc_curve25519_set_nonblock) and implementation with state machine for iterative scalar multiplication in fe_low_mem.c
  • Integrates non-blocking X25519 into TLS layer for key share generation and ECDH operations during handshake
  • Fixes C90 mixed-declaration violations in SP ECC non-blocking code across multiple architecture files by moving typedef declarations before statements
  • Adds new standalone async TLS client/server examples with Makefile, user settings, and CI workflow
  • Updates ED25519 certificate keys to use proper PKCS#8 private key format instead of SubjectPublicKeyInfo

Reviewed changes

Copilot reviewed 37 out of 37 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
wolfssl/wolfcrypt/fe_operations.h Declares non-blocking function prototypes for fe_inv and curve25519
wolfssl/wolfcrypt/curve25519.h Defines non-blocking context structures and API
wolfssl/wolfcrypt/async.h Adds X25519 async device support structures and markers
wolfcrypt/src/fe_low_mem.c Implements non-blocking state machine for curve25519 scalar multiplication
wolfcrypt/src/curve25519.c Adds non-blocking key gen and shared secret wrappers with async integration
wolfcrypt/src/async.c Implements async device handlers for X25519 operations
wolfcrypt/test/test.c Adds X25519 non-blocking test cases and updates existing tests for async support
src/tls.c Integrates X25519 non-blocking support in key share generation and ECDH processing
src/internal.c Allocates non-blocking contexts for X25519 keys and updates cleanup
src/ssl.c Maps MP_WOULDBLOCK error to WC_PENDING_E
wolfcrypt/src/sp_*.c Fixes C90 compliance by moving typedef before statements
tests/utils.c, tests/api.c Handles MP_WOULDBLOCK errors in handshake loops
wolfcrypt/src/asn.c Fixes non-blocking context allocation to only occur with valid async device
wolfssl/certs_test.h Updates ED25519 keys to proper PKCS#8 private key format
gencertbuf.pl Updates certificate paths to use -priv.der files
examples/async/* New standalone async examples with user settings and Makefile
.github/workflows/async-examples.yml CI workflow testing async examples with multiple configurations
configure.ac Adds --enable-curve25519=nonblock option
examples/configs/user_settings_curve25519nonblock.h Example configuration for X25519 non-blocking
.wolfssl_known_macro_extras Adds NET_GETDEVRANDOM and WC_ASYNC_NO_X25519 macros

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dgarske
Copy link
Contributor Author

dgarske commented Feb 7, 2026

Jenkins retest this please "ChannelClosedException"

@dgarske dgarske assigned wolfSSL-Bot and unassigned wolfSSL-Bot Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants